import 'package:file_preview/file_preview.dart';
import 'package:flutter/material.dart';
import 'package:live_music/models/moment_detail_model.dart';
import 'package:url_launcher/url_launcher.dart';

class FilePreviewPage extends StatefulWidget {
  const FilePreviewPage({Key key, this.momentId, this.fileItem})
      : super(key: key);
  final FileClass fileItem;
  final int momentId;
  @override
  _FilePreviewPageState createState() => _FilePreviewPageState();
}

class _FilePreviewPageState extends State<FilePreviewPage> {
  void initState() {
    super.initState();
    openUrl();
  }

  openUrl() async {
    if (await canLaunch(widget.fileItem.url)) {
      await launch(widget.fileItem.url);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          widget.fileItem.title,
        ),
      ),
      body: Container(
        alignment: Alignment.topLeft,
        child: FilePreviewWidget(
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.height,
          path: widget.fileItem.url,
          callBack: FilePreviewCallBack(onShow: () {
            print("文件打开成功");
          }, onDownload: (progress) {
            print("文件下载进度$progress");
          }, onFail: (code, msg) {
            print("文件打开失败 $code  $msg");
          }),
        ),
      ),
    );
  }
}
